<template>
  <div class="plan-selection">
    <v-header :user="userInfo" :createdUser="createdUser"></v-header>
    <div class="content-iframe" id="school-list">
      <div class="add-student-info clearfix">
        <div class="add-info">
          <span class="space-left">学生信息</span>
          <span>/</span>
          <span>{{studentInfo.name}}</span>
          <span>/</span>
          <span>{{studentInfo.major==1?'文史':'理工'}}</span>
          <span>/</span>
          <span>{{studentInfo.score}}</span>
          <span>/</span>
          <span>{{studentInfo.precedence}}</span>
          <div class="search-packup pull-right" @click="packUp">
            <span v-show="showSearch">收起</span>
            <span v-show="showSearch" class="glyphicon glyphicon-menu-up"></span>
            <span v-show="!showSearch">展开</span>
            <span v-show="!showSearch" class="glyphicon glyphicon-menu-down"></span>
          </div>
        </div>
      </div>
      <div class="search-nav">
        <div class="nav">
          <div class="clearfix">
            <div class="nav-label pull-left">院校性质：</div>
            <ul class="label-con">
              <li class="label-object" v-for="(item, index) in schoolType" :class="{active: item.current}"
                  v-on:click="searchLabel(item)">{{item.typeName}}
              </li>
            </ul>
          </div>

          <div class="clearfix">
            <div class="nav-label pull-left">院校层级：</div>
            <ul class="label-con">
              <li class="label-object" v-for="(item, index) in schoolLevel" :class="{active: item.current}"
                  v-on:click="searchLevel(item)">{{item.levelName}}
              </li>
            </ul>
          </div>

          <div class="clearfix">
            <div class="nav-label pull-left">所在省份：</div>
            <ul class="label-con">
              <li class="label-object" v-for="(item, index) in schoolProvince" :class="{active: item.current}"
                  v-on:click="searchProvince(item)">{{item.pvcName}}
              </li>
              <li class="label-object">展开更多</li>
            </ul>
          </div>

          <div class="clearfix">
            <div class="nav-label pull-left">专业选择：</div>
            <ul class="label-con">
              <input type="text" class="label-input label-green" id="exampleInputEmail1" v-model="majorFir"
                     placeholder="搜索内容"/>
              <input type="text" class="label-input label-red" id="exampleInputEmail2" v-model="majorSec"
                     placeholder="搜索内容"/>
              <input type="text" class="label-input label-blue" id="exampleInputEmail3" v-model="majorThr"
                     placeholder="搜索内容"/>
              <div class="search-label" v-on:click="searchMajor()">
                <span class="glyphicon glyphicon-search"></span>
              </div>
              <div style="display: inline-block" v-on:click="resetSearch()">
                <button class="btn btn-default btn-sm">重置</button>
              </div>
            </ul>
          </div>
        </div>
      </div>
      <div class="school-list">
        <div class="container-fluid" style="padding-left: 0;padding-right: 0;">
          <div class="row-fluid">
            <div class="span12">
              <table class="table table-bordered">
                <thead>
                <tr>
                  <th class="w-5" style="cursor: pointer;">代码</th>
                  <th class="school-name">院校名称</th>
                  <th class="w-4">排名</th>
                  <th colspan=3>2015/2016/2017 计划/投档|最低分|最低线差|最低位次</th>
                  <th class="organizer" style="">主管单位</th>
                  <th class="list-city">所在市</th>
                  <th class="w-6 school-level">层级</th>
                  <!--<th class="w-8">类型</th>-->
                  <th class="major-plan">专业安排</th>
                  <th class="w-6">18计</th>
                  <th class="w-3">选</th>
                </tr>
                </thead>
                <tbody v-for="(item, index) in schoolInfo ">
                <tr
                  :class="{bgGray: item.color==1,bgSearchFir: item.color==2,bgSearchSec: item.color==3,bgSearchThr: item.color==4}">
                  <td style="cursor: pointer;" v-on:click="showMajor(item, index)">{{item.code}}</td>
                  <td :id="item.code + '_dsc'" @mouseover="showDsc(item)" @mouseout="hideDsc(item)"
                      style="cursor: pointer;">
                    {{item.schoolName}}
                    <div class="dscTip">
                      {{item.describe}}
                    </div>
                    <div class="top-arrow"></div>
                  </td>
                  <td>{{item.sortNum}}</td>
                  <td class="text-right">{{item.msg2015}}</td>
                  <td class="text-right">{{item.msg2016}}</td>
                  <td class="text-right">{{item.msg2017}}</td>
                  <td style="font-size: 12px">{{item.manager.length>4?item.manager.substr(0, 4):item.manager}}</td>
                  <td style="font-size: 12px">{{item.city}}</td>
                  <td :class="{colorMian: item.level.current}" style="font-size: 12px">{{item.level.name}}</td>
                  <!--<td :class="{colorMian: item.property.current}">{{item.property.name}}</td>-->
                  <td style="font-size: 12px">3-3-3-3-3</td>
                  <td>{{item.planStatus2018}}↑</td>
                  <td :id="item.code + '_select-school'" @mouseover="showSelectSchool(item)"
                      @mouseout="hideSelectSchool(item)" style="cursor: pointer;">
                    <i :id="item.code + '_checkmark'" class="glyphicon glyphicon-ok color-9"></i>
                    <p class="hock-volunteername color-main" :id="item.code + '_volunteername'">
                      {{item.volunteerName}}</p>
                    <div class="select-school">
                      <p v-for="(itemType, index) in voluntaryType" @click="chooseSchool(itemType, item)">
                        {{itemType}}</p>
                    </div>
                    <div class="select-top-arrow"></div>
                  </td>
                </tr>
                <tr v-show="item.majorInfo">
                  <td colspan=13 class="pad0">
                    <!-- 专业表 -->
                    <table class="table table-bordered school-major major-table" :id="item.code + '_mojar'">
                      <thead>
                      <tr class="tr-bor-t">
                        <th style="width: 4.5%;">代码</th>
                        <th style="width: 17.6%;">专业名称</th>
                        <th>层级</th>
                        <th colspan=3>2015/2016/2017 计划/投档|最低分|最低线差|最低位次</th>
                        <th style="width: 4%;">18计</th>
                        <th>选</th>
                        <th>报考限制</th>
                      </tr>
                      </thead>
                      <tbody :id="item.code + '_mojar_tbody'">
                      <tr v-for="(majorItem, marjorIndex) in item.majorInfo">
                        <td>{{majorItem.code}}</td>
                        <td class="marjor-name" :id="majorItem.code + '_' + marjorIndex + '_majordsc'"
                            @mouseover="showMajorDsc(item, marjorIndex)"
                            @mouseout="hideMajorDsc(item, marjorIndex)">
                          {{majorItem.majorName}}
                          <div class="major-dsc-tip">专业描述</div>
                          <div class="major-dsc-arrow"></div>
                        </td>
                        <td>{{majorItem.level}}</td>
                        <td class="text-right">{{majorItem.msg2015}}</td>
                        <td class="text-right">{{majorItem.msg2016}}</td>
                        <td class="text-right">{{majorItem.msg2017}}</td>
                        <td>{{majorItem.planStatus2018}}↑</td>
                        <td :id="item.code + '_' + marjorIndex + '_select-major'"
                            @mouseover="showSelectMajor(item, majorItem, marjorIndex)"
                            @mouseout="hideSelectMajor(item, majorItem, marjorIndex)"
                            style="width: 3%;cursor: pointer;">
                          <i :id="item.code + '_' + marjorIndex + '_checkmark_major'"
                             class="glyphicon glyphicon-ok color-9"></i>
                          <p class="hock-volunteername color-main"
                             :id="item.code + '_' + marjorIndex + '_majorvolunteer'"></p>
                          <div class="select-school">
                            <p v-for="(itemTypeMajor, index) in voluntaryMajorType"
                               @click="chooseMajorType(itemTypeMajor, majorItem, marjorIndex)">{{itemTypeMajor}}</p>
                          </div>
                          <div class="select-top-arrow"></div>
                        </td>
                        <td>报考限制</td>
                      </tr>
                      </tbody>
                    </table>
                  </td>
                </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>
        <!-- 右侧悬浮 -->
        <div class="right-operate">
          <div class="modify" @click="redoPlan()">重做</div>
          <div class="confirm" @click="submitPlan(2)">保存</div>
          <div class="download" @click="submitPlan(1)">提交</div>
        </div>
      </div>
    </div>
    <v-footer></v-footer>
  </div>
</template>

<script type="text/ecmascript-6">
  import header from '../header/header.vue';
  import footer from '../footer/footer.vue';
  import $ from 'jquery';
  import Vue from 'vue';

  export default {
    name: 'plan-selection',
    components: {
      'v-header': header,
      'v-footer': footer
    },
    data() {
      return {
        userInfo: '',
        createdUser: '',
        showSearch: true,
        schoolInfo: [],
        schoolType: [
          {
            typeName: '综合类',
            current: false
          },
          {
            typeName: '理工类',
            current: false
          },
          {
            typeName: '财经类',
            current: false
          },
          {
            typeName: '师范类',
            current: false
          },
          {
            typeName: '语言类',
            current: false
          }
        ],
        schoolLevel: [
          {
            levelName: '985',
            current: false
          },
          {
            levelName: '211',
            current: false
          },
          {
            levelName: '小211',
            current: false
          },
          {
            levelName: '省重点',
            current: false
          },
          {
            levelName: '师范高职',
            current: false
          }
        ],
        schoolProvince: [
          {
            pvcName: '陕西省',
            current: false
          },
          {
            pvcName: '北京市',
            current: false
          },
          {
            pvcName: '上海市',
            current: false
          },
          {
            pvcName: '湖北省',
            current: false
          },
          {
            pvcName: '浙江省',
            current: false
          }
        ],
        majorFir: '',
        majorSec: '',
        majorThr: '',
        searchFir: [],
        searchFirComp: false,
        searchSec: [],
        searchSecComp: false,
        searchThr: [],
        searchThrComp: false,
        voluntaryType: ['备选', '志愿A', '志愿B', '志愿C', '志愿D', '志愿E', '志愿F', '取消'],
        voluntaryMajorType: ['备选', '专业1', '专业2', '专业3', '专业4', '专业5', '专业6', '取消'],
        stuNo: '',
        schemeInfo: [],
        studentInfo: {
          // id: 0,                //类型：Number  必有字段  备注：无
          createdUser: '',                //类型：Number  必有字段  备注：当前登录的用户id
          name: '',                //类型：String  可有字段  备注：姓名
          examNo: '',                //类型：String  可有字段  备注：准考证号码
          cardNo: '',                //类型：String  可有字段  备注：身份证号码
          major: '',                //类型：Number  可有字段  备注：科类0:理科1:文科
          sex: '',                //类型：Number  可有字段  备注：性别0:男1:女
          school: '',                //类型：String  可有字段  备注：所在学校
          rank: '',                //类型：Number  可有字段  备注：排名
          stuNum: '',                //类型：Number  可有字段  备注：年纪人数
          stuType: '',                //类型：Number  可有字段  备注：类型0:应届1:往届
          score: '',                //类型：Number  可有字段  备注：分数
          precedence: '',                //类型：Number  可有字段  备注：位次
          policy: '',                //类型：String  可有字段  备注：政策
          limitContent: '',                //类型：String  可有字段  备注：受限制条件
          other: '',                //类型：String  可有字段  备注：其他信息
          chinese: '',                //类型：Number  可有字段  备注：语文成绩
          english: '',                //类型：Number  可有字段  备注：英语成绩
          math: '',                //类型：Number  可有字段  备注：数学成绩
          physics: '',                //类型：Number  可有字段  备注：物理/政治成绩
          chemistry: '',                //类型：Number  可有字段  备注：化学/历史成绩
          biology: '',                //类型：Number  可有字段  备注：生物/地理成绩
          comprehensive: ''                //类型：Number  可有字段  备注：综合成绩
        }
      };
    },
    created() {
      this.fetchData();
    },
    methods: {
      // 获取页面url参数
      fetchData() {
        let username = this.$utils.getUrlKey('username');
        this.userInfo = username;
        this.createdUser = this.$utils.getUrlKey('createdUser');
        this.stuNo = this.$utils.getUrlKey('stuNo');
        this.getSchool();
        this.getStudentDetail();
      },
      // 获取学生档案详情
      getStudentDetail() {
        let self = this;
        let params = new URLSearchParams();
        params.append('userId', self.createdUser);
        params.append('stuNo', self.stuNo);
        self.$http.post(this.HOST + 'mendao/getStuByStuNo', params).then((response) => {
          if (response.data.code == 1) {
            let info = response.data.data;
            self.studentInfo = {
              createdUser: info.createdUser,
              name: info.name,
              examNo: info.examNo,
              cardNo: info.cardNo,
              major: info.major,
              sex: info.sex,
              school: info.school,
              rank: info.rank,
              stuNum: info.stuNum,
              stuType: info.stuType,
              score: info.score,
              precedence: info.precedence,
              policy: info.policy,
              limitContent: info.limitContent,
              other: info.other,
              chinese: info.chinese,
              english: info.english,
              math: info.math,
              physics: info.physics,
              chemistry: info.chemistry,
              biology: info.biology,
              comprehensive: info.comprehensive
            };
            Vue.set(this.studentInfo, 'id', this.$utils.getUrlKey('stuNo'));
          }
          ;
        }, (response) => {
          console.log('数据请求失败');
        });
      },
      // 搜索条件展开收起
      packUp() {
        if (this.showSearch) {
          $('.search-nav').css('display', 'none');
        } else {
          $('.search-nav').css('display', 'block');
        }
        this.showSearch = !this.showSearch;
      },
      // 获取学校
      getSchool() {
        var self = this;
        this.$http.get(this.HOST + 'mendao/getSchool', {}).then(function (response) {
          if (response.data.code == 1) {
            self.schoolInfo = response.data.list;
            for (var i = 0; i < self.schoolInfo.length; i++) {
              self.schoolInfo[i].majorInfo = '';
              Vue.set(self.schoolInfo[i], 'volunteerName', '');
              Vue.set(self.schoolInfo[i], 'schemeChange', 1);
            }
            self.getPlan(); // 获取已经制定好的方案
          } else {
            console.log('数据请求失败1');
          }
        })
          .catch(function (error) {
            console.log(error);
          });

      },
      // 显示专业
      showMajor: function (item, index) {
        item.isShowMajor = !item.isShowMajor;
        if (item.isShowMajor) {
          this.getMajor(item, index);
          $('#' + item.code + '_mojar').show();
        } else {
          $('#' + item.code + '_mojar').hide();
        }
      },
      // 院校性质标签
      searchLabel(item) {
        for (var i = 0; i < this.schoolType.length; i++) {
          this.schoolType[i].current = false;
        }
        if (item) {
          item.current = true;
          // 列表中对应的地方高亮
          this.listPosition('property', item.typeName);
        }
      },
      // 院校层级标签
      searchLevel(item) {
        for (var i = 0; i < this.schoolLevel.length; i++) {
          this.schoolLevel[i].current = false;
        }
        if (item) {
          item.current = true;
          // 列表中对应的地方高亮
          this.listPosition('level', item.levelName);
        }
      },
      // 院校层级标签
      searchProvince(item) {
        for (var i = 0; i < this.schoolProvince.length; i++) {
          this.schoolProvince[i].current = false;
        }
        if (item) {
          item.current = true;
          // 列表中对应的地方高亮
        }
      },
      // 定位在列表中的位置并且高亮
      listPosition(key, value) {
        for (var i = 0; i < this.schoolInfo.length; i++) {
          if (key == 'property') {
            this.schoolInfo[i].property.current = false;
            if (this.schoolInfo[i].property.name.slice(0, 3) == value) {
              this.schoolInfo[i].property.current = true;
            }
          }
          if (key == 'level') {
            this.schoolInfo[i].level.current = false;
            if (this.schoolInfo[i].level.name == value) {
              this.schoolInfo[i].level.current = true;
            }
          }
        }

      },
      // 获取专业
      getMajor(item, index) {
        var self = this;
        // 请求后端
        this.$http.post(this.HOST + '/mendao/getMajor?type=1&schoolCode=' + item.code, {}).then(function (res) {
          if (res.data.code == 1) {
            item.majorInfo = res.data.list;
            for (let i = 0; i < item.majorInfo.length; i++) {
              Vue.set(item.majorInfo[i], 'majorType', '');
            }
            let info = item;
            Vue.set(self.schoolInfo, index, info);
            console.log('数据请求成功');
            if (self.schemeInfo.length > 0) {
              setTimeout(function () {
                self.formatMajor(item.majorInfo, item.code);
              }, 500);
            }
          } else {
            console.log('数据请求失败');
          }

        }, function (res) {
          alert(res.status)
        });
      },
      // 搜索专业
      searchMajor() {
        var self = this;
        if (this.majorFir) {
          this.searchSchool(2, this.majorFir);
        }
        if (this.majorSec) {
          this.searchSchool(3, this.majorSec);
        }
        if (this.majorThr) {
          this.searchSchool(4, this.majorThr);
        }

      },
      // 搜索方法
      searchSchool(searchType, major) {
        var self = this;
        // 请求后端
        this.$http.get(this.HOST + '/mendao/getSchool?type=1&major=' + major, {
          type: 1,
          major: major
        }).then(function (res) {
          if (parseInt(res.data.code) === 1) {
            if (searchType === 2) {
              self.searchFir = res.data.list;
            } else if (searchType === 3) {
              self.searchSec = res.data.list;
            } else if (searchType === 4) {
              self.searchThr = res.data.list;
              self.formatData();
            }

            if (self.searchFir.length > 0 && (self.searchSec.length == 0 && self.searchThr == 0)) {
              self.formatData();
            }
            if (self.searchFir.length > 0 && self.searchSec.length > 0 && self.searchThr == 0) {
              self.formatData();
            }

            if (self.searchFir.length == 0 && (self.searchSec.length == 0 && self.searchThr == 0)) {
              self.schoolInfo = [];
            }

          } else {
            console.log('数据请求成功');
          }
        })
          .catch(function (error) {
            console.log(error);
          });
      },
      // 搜索数据整理
      formatData() {
        let self = this;
        // 去重方法
        var tempSec = self.searchSec;
        var tempThr = self.searchThr;

        // 第一个搜索框有内容
        if (this.majorFir && !this.majorSec && !this.majorThr) {
          console.log("第一搜索框都有内容" + JSON.stringify(self.searchFir));
          for (var i = 0; i < self.searchFir.length; i++) {
            self.searchFir[i].majorInfo = '';
            self.searchFir[i].color = 2;
          }
          self.schoolInfo = self.searchFir;
          return;
        }
        // 第一个和第二个搜索框有内容
        if (this.majorFir && this.majorSec && !this.majorThr) {
          self.searchSec = this.removeRepeat(self.searchFir, tempSec);
          for (var i = 0; i < self.searchFir.length; i++) {
            self.searchFir[i].majorInfo = '';
            self.searchFir[i].color = 2;
          }
          for (var i = 0; i < self.searchSec.length; i++) {
            self.searchSec[i].majorInfo = '';
            self.searchSec[i].color = 3;
          }
          self.schoolInfo = self.searchFir.concat(self.searchSec);
          return;
        }
        // 三个搜索框有内容
        if (this.majorFir && this.majorSec && this.majorThr) {
          var tempArr = this.removeRepeat(self.searchFir, tempThr);
          self.searchThr = this.removeRepeat(self.searchSec, tempArr);
          for (var i = 0; i < self.searchFir.length; i++) {
            self.searchFir[i].majorInfo = '';
            self.searchFir[i].color = 2;
          }
          for (var i = 0; i < self.searchSec.length; i++) {
            self.searchSec[i].majorInfo = '';
            self.searchSec[i].color = 3;
          }
          for (var i = 0; i < self.searchThr.length; i++) {
            self.searchThr[i].majorInfo = '';
            self.searchThr[i].color = 4;
          }
          self.schoolInfo = self.searchFir.concat(self.searchSec).concat(self.searchThr);
          return;
        }
      },
      // 搜索去重方法
      removeRepeat(arr1, arr2) {
        var finalArr = [];
        for (var i = 0; i < arr2.length; i++) {
          for (var j = 0; j < arr1.length; j++) {
            if (arr2[i].code !== arr1[i].code) {
              finalArr.push(arr2[i]);
            }
          }
        }
        return finalArr;
      },
      // 显示学校简介
      showDsc(item) {
        $('#' + item.code + '_dsc').children('div').show();
      },
      hideDsc(item) {
        $('#' + item.code + '_dsc').children('div').hide();
      },
      // 显示专业简介
      showMajorDsc(item, index) {
        $('#' + item.code + '_' + index + '_majordsc').children('div').show();
      },
      hideMajorDsc(item, index) {
        $('#' + item.code + '_' + index + '_majordsc').children('div').hide();
      },
      // 显示学校选择方案
      showSelectSchool(item) {
        $('#' + item.code + '_select-school').children('div').show();
      },
      hideSelectSchool(item) {
        $('#' + item.code + '_select-school').children('div').hide();
      },
      // 显示专业选择方案
      showSelectMajor(item, majorItem, index) {
        $('#' + item.code + '_' + index + '_select-major').children('div').show();
      },
      hideSelectMajor(item, majorItem, index) {
        $('#' + item.code + '_' + index + '_select-major').children('div').hide();
      },
      /**
       * 重置搜索
       */
      resetSearch() {
        this.searchLabel(false);
        this.searchLevel(false);
        this.searchProvince(false);
        this.majorFir = '';
        this.majorSec = '';
        this.majorThr = '';
        this.getSchool();
      },
      /**
       * 志愿选择-学校
       */
      chooseSchool(typeName, schoolItem) {
        let self = this;
        let tempName = '';
        for (let i = 0; i < self.schoolInfo.length; i++) {
          if (self.schoolInfo[i].code == schoolItem.code) {
            switch (typeName) {
              case '备选':
                tempName = '备';
                break;
              case '志愿A':
                tempName = 'A';
                break;
              case '志愿B':
                tempName = 'B';
                break;
              case '志愿C':
                tempName = 'C';
                break;
              case '志愿D':
                tempName = 'D';
                break;
              case '志愿E':
                tempName = 'E';
                break;
              case '志愿F':
                tempName = 'F';
                break;
              case '取消':
                tempName = '';
                break;
              default:
                break;
            }
            if (typeName == '取消') {
              self.hideSelectSchool(schoolItem);
              Vue.set(self.schoolInfo[i], 'volunteerName', '');
              $('#' + schoolItem.code + '_checkmark').show();
              $('#' + schoolItem.code + '_volunteername').hide();
              return;
            }
            self.hideSelectSchool(self.schoolInfo[i]);
            Vue.set(self.schoolInfo[i], 'volunteerName', tempName);
            $('#' + schoolItem.code + '_checkmark').hide();
            $('#' + schoolItem.code + '_volunteername').show();
          }
        }
      },
      /**
       * 志愿选择-专业
       */
      chooseMajorType(typeName, majorItem, index) {
        let self = this;
        let tempName = '';
        for (let i = 0; i < self.schoolInfo.length; i++) {
          if (self.schoolInfo[i].code == majorItem.code) {
            for (let j = 0; j < self.schoolInfo[i].majorInfo.length; j++) {
              if (self.schoolInfo[i].volunteerName == '') {  // 判断是否选中上级学校
                alert("请先选择学校");
                return;
              }
              if (self.schoolInfo[i].majorInfo[j].majorName == majorItem.majorName) {
                switch (typeName) {
                  case '备选':
                    tempName = '备';
                    break;
                  case '专业1':
                    tempName = '1';
                    break;
                  case '专业2':
                    tempName = '2';
                    break;
                  case '专业3':
                    tempName = '3';
                    break;
                  case '专业4':
                    tempName = '4';
                    break;
                  case '专业5':
                    tempName = '5';
                    break;
                  case '专业6':
                    tempName = '6';
                    break;
                  case '取消':
                    tempName = '';
                    break;
                  default:
                    break;
                }

                self.hideSelectMajor(majorItem, index);
                self.hideSelectMajor(self.schoolInfo[i].majorInfo[j], index);
                Vue.set(self.schoolInfo[i].majorInfo[j], 'majorType', tempName);
                if (tempName == '备') {
                  Vue.set(self.schoolInfo[i].majorInfo[j], 'majorType', 7);
                }
                $('#' + majorItem.code + '_' + index + '_majorvolunteer').text(tempName);
                if (typeName == '取消') {
                  $('#' + majorItem.code + '_' + index + '_checkmark_major').show();
                  $('#' + majorItem.code + '_' + index + '_majorvolunteer').hide();
                  return;
                }
                $('#' + majorItem.code + '_' + index + '_checkmark_major').hide();
                $('#' + majorItem.code + '_' + index + '_majorvolunteer').show();
              }
            }
          }
        }
      },
      // 获取已制定的方案
      getPlan() {
        let self = this;
        let params = new URLSearchParams();
        params.append('stuNo', self.stuNo);
        params.append('userId', self.createdUser);
        this.$http.post(this.HOST + 'mendao/getStuScheme', params).then(function (response) {
          if (response.data.code == 1) {
            self.schemeInfo = response.data.list;
            // 整理学校数据
            if (self.schemeInfo.length > 0) {
              for (let k = 0; k < self.schemeInfo.length; k++) {
                for (let i = 0; i < self.schoolInfo.length; i++) {
                  if (self.schemeInfo[k].schoolCode == self.schoolInfo[i].code) {
                    self.schoolInfo[i].volunteerName = self.schemeInfo[k].schemeName;
                    $('#' + self.schoolInfo[i].code + '_checkmark').hide();
                    $('#' + self.schoolInfo[i].code + '_volunteername').show();
                    Vue.set(self.schoolInfo[i], 'schemeChange', self.schemeInfo[k].schemeChange);
                    if (self.schemeInfo[k].majorList.length > 0) {
                      for (let j = 0; j < self.schemeInfo[k].majorList.length; j++) {
                        self.getMajor(self.schoolInfo[i], i);
                      }
                    }

                  }
                }
              }
            }
          } else {
            alert(response.data.msg);
            console.log('获取已制定的方案数据请求失败');
          }
        })
          .catch(function (error) {
            console.log(error);
          });

      },
      // 整理专业数据
      formatMajor(majorList, code) {
        let self = this;
        for (let i = 0; i < self.schemeInfo.length; i++) {
          if (self.schemeInfo[i].schoolCode == code) {
            for (let j = 0; j < self.schemeInfo[i].majorList.length; j++) {
              for (let k = 0; k < majorList.length; k++) {
                if (self.schemeInfo[i].majorList[j].majorName == majorList[k].majorName) {
                  majorList[k].majorType = self.schemeInfo[i].majorList[j].majorNum;
                  $('#' + majorList[k].code + '_' + k + '_majorvolunteer').text(self.schemeInfo[i].majorList[j].majorNum);
                  if(self.schemeInfo[i].majorList[j].majorNum == 7){
                    majorList[k].majorType = '备';
                    $('#' + majorList[k].code + '_' + k + '_majorvolunteer').text('备');
                  }

                  $('#' + majorList[k].code + '_' + k + '_checkmark_major').hide();
                  $('#' + majorList[k].code + '_' + k + '_majorvolunteer').show();
                }
              }
            }
          }
        }
        // return majorType;
      },
      // 重做
      redoPlan() {
        let self = this;
        for (let i = 0; i < self.schoolInfo.length; i++) {
          self.schoolInfo[i].volunteerName = '';
          $('#' + self.schoolInfo[i].code + '_checkmark').show();
          $('#' + self.schoolInfo[i].code + '_volunteername').hide();
          for (let j = 0; j < self.schoolInfo[i].majorInfo.length; i++) {
            self.schoolInfo[i].majorInfo[i].majorType = '';
            $('#' + self.schoolInfo[i].majorInfo[j].code + '_' + j + '_checkmark_major').show();
            $('#' + self.schoolInfo[i].majorInfo[j].code + '_' + j + '_majorvolunteer').hide();
            Vue.set(self.schoolInfo[i].majorInfo[j], 'majorType', '');
            $('#' + self.schoolInfo[i].majorInfo[j].code + '_' + j + '_majorvolunteer').text('');
          }
        }
      },
      /**
       * 提交志愿方案
       */
      submitPlan(type) {
        let self = this;
        let paramsAll = {
          "schemes": [                //类型：Array  必有字段  备注：无
          ],
          "stuNo": self.stuNo                //类型：String  必有字段  备注：学生编号
        };
        for (let i = 0; i < self.schoolInfo.length; i++) {
          if (self.schoolInfo[i].volunteerName) {
            var tempSchoolObj = {                //类型：Object  必有字段  备注：无
              "schemeName": self.schoolInfo[i].volunteerName,                //类型：String  必有字段  备注：报考方案名称（方案A）
              "schemeNum": '',                //类型：Number  必有字段  备注：方案编号
              "schoolCode": self.schoolInfo[i].code,                //类型：String  必有字段  备注：学校code
              "schoolName": self.schoolInfo[i].schoolName,                //类型：String  必有字段  备注：学校名称
              "majorList": [                //类型：Array  必有字段  备注：报考专业列表
              ],
              "schemeChange": self.schoolInfo[i].schemeChange                //类型：Number  必有字段  备注：是否服从调剂0:是1:否
            };
            switch (tempSchoolObj.schemeName) {
              case '备':
                tempSchoolObj.schemeNum = 7;
                break;
              case 'A':
                tempSchoolObj.schemeNum = 1;
                break;
              case 'B':
                tempSchoolObj.schemeNum = 2;
                break;
              case 'C':
                tempSchoolObj.schemeNum = 3;
                break;
              case 'D':
                tempSchoolObj.schemeNum = 4;
                break;
              case 'E':
                tempSchoolObj.schemeNum = 5;
                break;
              case 'F':
                tempSchoolObj.schemeNum = 6;
                break;
              default:
                break;
            }

            for (let j = 0; j < self.schoolInfo[i].majorInfo.length; j++) {
              if (self.schoolInfo[i].majorInfo[j].majorType) {
                let tempMajorObj = {                //类型：Object  必有字段  备注：无
                  "majorCode": self.schoolInfo[i].majorInfo[j].code,                //类型：String  必有字段  备注：专业编号
                  "majorName": self.schoolInfo[i].majorInfo[j].majorName,                //类型：String  必有字段  备注：专业名称
                  "majorNum": self.schoolInfo[i].majorInfo[j].majorType,                //类型：String  必有字段  备注：专业名称
                };
                if(self.schoolInfo[i].majorInfo[j].majorType == '备'){
                  tempMajorObj.majorNum = 7;
                }
                tempSchoolObj.majorList.push(tempMajorObj);
              }
            }
            paramsAll.schemes.push(tempSchoolObj);
          }
        }
        // 请求接口提交
        let params = new URLSearchParams();
        params.append('data', JSON.stringify(paramsAll));
        params.append('stuNo', self.stuNo);
        self.$http.post(this.HOST + 'mendao/saveStuScheme', params).then((response) => {
          if (response.data.code == 1) {
            alert("指定方案成功");
            console.log("请求成功");
            if (type == 1) {  // 提交
              this.$router.push({
                path: '/studentPlan', query: {
                  username: this.userInfo,
                  createdUser: this.createdUser,
                  stuNo: self.stuNo
                }
              });
            }
          }
        }, (response) => {
          console.log('数据请求失败');
        });
      }
    },
  };
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .plan-selection
    width: 100%
    min-height: 100vh
    p {
      margin: 0;
    }
    .content-iframe {
      width: 100%;
      top: 50px;
      bottom: 60px;
      position: relative;
    }
    .content-iframe .school-list .right-operate {
      position: fixed
      /*right: 50px*/
      right: 5px
      top: 50%
      margin-top: -125px
      width: 70px
      height: 250px
    }
    .content-iframe .school-list .right-operate div {
      width: 70px;
      height: 70px;
      line-height: 70px;
      border-radius: 100px;
      color: #fff;
      font-size: 14px;
      text-align: center;
      box-shadow: 0px 0px 8px 0px rgba(170, 170, 170, 1);
    }
    .content-iframe .school-list .right-operate .modify {
      cursor: pointer
      background-color: rgba(0, 150, 136, 1);
    }
    .content-iframe .school-list .right-operate .confirm {
      cursor: pointer
      margin-top: 20px
      background-color: rgba(237, 108, 36, 1)
    }
    .content-iframe .school-list .right-operate .download {
      cursor: pointer
      margin-top: 20px
      background-color: rgba(37, 155, 36, 1);
    }
    .content-iframe .add-student-info {
      position: fixed;
      width: 100%;
      height: 37px;
      top: 46px;
      background-color: #fff;
      color: #E65A1E;
      border-bottom: 1px solid #bbbbbb;
      z-index: 3;
    }

    .content-iframe .add-student-info .add-info {
      width: 1190px;
      margin: 0 auto;
      height: 36px;
      line-height: 36px;
      font-size: 14px;
    }

    .content-iframe .add-student-info .search-packup {
      padding: 3px 12px;
      color: #E65A1E;
      font-size: 14px;
      vertical-align: middle;
      cursor: pointer;
    }

    .content-iframe .add-student-info .space-left {
      margin-left: 63px;
    }

    .content-iframe .search-nav {
      position: fixed;
      width: 100%;
      display: none;
      margin: 0 auto;
      top: 83px;
      padding: 10px 0;
      border-bottom: 2px solid #bbb;
      overflow-y: hidden;
      background: #fff;
      z-index: 3;
    }

    .content-iframe .search-nav .nav {
      position: relative;
      width: 1190px;
      margin: 0 auto;
    }

    .content-iframe .search-nav .nav-label {
      min-height: 28px;
      line-height: 28px;
      margin-right: 20px;
    }

    .content-iframe .search-nav .btn {
      padding: 3px 12px;
      border-radius: 15px;
    }

    .content-iframe .search-nav .btn:hover {
      color: #E65A1E;
      background-color: #fff;
      border-color: #E65A1E;
    }

    .content-iframe .search-nav .btn:focus, .btn:active:focus {
      outline: none;
      border-color: #E65A1E;
      color: #E65A1E;
      box-shadow: none;
      background-color: #fff;
    }

    .content-iframe .search-nav .btn:active,
    .content-iframe .search-nav .btn.active {
      border-color: #E65A1E;
      color: #E65A1E;
      box-shadow: none;
      background-color: #fff;
    }

    .label-con {
      display: block;
      padding-left: 70px;
    }

    .content-iframe .search-nav .label-object {
      display: inline-block;
      padding: 3px 12px;
      border-radius: 15px;
      margin-bottom: 0;
      font-size: 14px;
      text-align: center;
      white-space: nowrap;
      vertical-align: middle;
      cursor: pointer;
      border: 1px solid #ccc;
      margin-right: 10px;
    }

    .content-iframe .search-nav .label-object:hover,
    .content-iframe .search-nav .label-object:focus,
    .content-iframe .search-nav .label-object:active,
    .content-iframe .search-nav .label-con .active {
      border-color: #E65A1E;
      color: #E65A1E;
      background-color: #fff;
    }

    .content-iframe .search-nav .label-input {
      display: inline-block;
      width: 200px;
      padding: 3px 12px;
      color: #555;
      background-color: #fff;
      border: 1px solid #ccc;
      border-radius: 15px;
      -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
      box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
      -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
      -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
      transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
    }

    .content-iframe .search-nav .label-input:focus {
      outline: none;
      box-shadow: none;
      background-color: #fff;
    }

    .content-iframe .search-nav .label-green {
      border-color: #8bc34a;
    }

    .content-iframe .search-nav .label-red {
      border-color: #ff4081;
    }

    .content-iframe .search-nav .label-blue {
      border-color: #3f51b5;
    }

    .content-iframe .search-nav .search-label {
      display: inline-block;
      padding: 2px 10px;
      color: #E65A1E;
      font-size: 20px;
      vertical-align: middle;
      cursor: pointer;
    }

    .content-iframe .school-list {
      width: 1190px;
      margin: auto;
      position: relative;
      overflow: auto;
      margin-top: 100px;
      padding-bottom: 100px;
    }

    .content-iframe .school-list .table-bordered > thead > tr > th {
      text-align: center;
    }

    .content-iframe .school-list .w-21 {
      width: 21%;
    }

    .content-iframe .school-list .w-12 {
      width: 12%;
    }

    .content-iframe .school-list .w-10 {
      width: 10%;
    }

    .content-iframe .school-list .w-8 {
      width: 8%;
    }

    .content-iframe .school-list .school-name {
      width: 32% !important;
    }

    .content-iframe .school-list .organizer {
      font-size: 12px;
      width: 9%;
    }

    .content-iframe .school-list .list-city {
      font-size: 12px;
      width: 8%;
    }

    .content-iframe .school-list .school-level {
      width: 6%;
      font-size: 12px;
    }

    .content-iframe .school-list .major-plan {
      width: 9%;
      font-size: 12px;
    }

    .content-iframe .school-list .w-5 {
      width: 5%;
    }

    .content-iframe .school-list .w-6 {
      width: 6%;
    }

    .content-iframe .school-list .w-4 {
      width: 4%;
    }

    .content-iframe .school-list .w-3 {
      width: 3%;
    }

    .content-iframe .school-list .table > tbody + tbody {
      border-top: 2px solid #bbb;
    }

    .content-iframe .school-list .table-bordered > thead > tr > th {
      border: 1px solid #bbb;
    }

    .content-iframe .school-list .table-bordered > tbody > tr > td {
      position: relative;
      border: 1px solid #bbb;
    }
    .content-iframe .school-list .table-bordered .color-main {
      color: #E65A1E
    }
    .content-iframe .school-list .table-bordered .color-9 {
      color: #999
    }
    .content-iframe .school-list .table-bordered .hock-volunteername {
      display: none
    }
    .content-iframe .school-list .table-bordered .select-school {
      display: none;
      position: absolute;
      top: 40px;
      right: 5px;
      width: 80px;
      height: auto;
      padding: 10px 0;
      text-align: center;
      color: #fff;
      border-radius: 4px;
      background: rgb(230, 90, 30);
      z-index: 2;
      p {
        line-height 30px
      }
    }
    .content-iframe .school-list .table-bordered .select-top-arrow {
      display: none;
      position: absolute;
      left: 0;
      top: 30px;
      width: 0;
      height: 0;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      border-bottom: 10px solid rgb(230, 90, 30);
      z-index: 2;
    }

    .content-iframe .school-list .bgGray {
      background-color: #dedede;
    }

    .content-iframe .school-list .bgSearchFir {
      background-color: #8bc34a;
    }

    .content-iframe .school-list .bgSearchSec {
      background-color: #ff4081;
    }

    .content-iframe .school-list .bgSearchThr {
      background-color: #3f51b5;
    }

    .content-iframe .school-list .school-code {
      cursor: pointer;
    }

    .content-iframe .school-list .dscTip {
      position: absolute;
      display: none;
      width: 710px;
      height: 100px;
      background-color: rgba(0, 0, 0, 0.6);
      z-index: 2;
      margin-top: 30px;
      margin-left: 4%;
      border-radius: 8px;
      padding: 8px;
      color: #fff;
      word-wrap: break-word;
      word-break: break-all;
      overflow-y: scroll;
    }
    .content-iframe .school-list .top-arrow {
      position: absolute;
      display: none;
      left: 87px;
      top: 43px;
      width: 0;
      height: 0;
      border-left: 15px solid transparent;
      border-right: 15px solid transparent;
      border-bottom: 15px solid rgba(0, 0, 0, 0.6);
    }

    .content-iframe .school-list .school-major {
      display: none;
    }

    .content-iframe .school-list .major-table {
      background: #f7d0d2 !important;
      margin-bottom: 0;
    }

    .major-table > tbody > tr > td,
    .major-table > tbody > tr > th,
    .major-table > tfoot > tr > td,
    .major-table > tfoot > tr > th,
    .major-table > thead > tr > td,
    .major-table > thead > tr > th {
      border: 1px solid #333;
    }

    .major-dsc-tip {
      position: absolute;
      display: none;
      width: 710px;
      height: 100px;
      background-color: rgba(0, 0, 0, 0.6);
      z-index: 2;
      margin-top: 30px;
      margin-left: 8%;
      border-radius: 8px;
      padding: 8px;
      color: #fff;
      word-wrap: break-word;
      word-break: break-all;
      overflow-y: scroll;
    }
    .major-dsc-arrow {
      position: absolute;
      display: none;
      left: 87px;
      top: 43px;
      width: 0;
      height: 0;
      border-left: 15px solid transparent;
      border-right: 15px solid transparent;
      border-bottom: 15px solid rgba(0, 0, 0, 0.6);
    }

    .marjor-name {
      cursor: pointer;
    }

    /*.marjor-name:hover .major-dsc-tip, .major-dsc-arrow{*/
    /*opacity: 1;*/
    /*}*/

    .content-iframe .school-list .pad0 {
      padding: 0;
    }

    .content-iframe .school-list .tr-bor-t {
      border: 1px solid #333;
    }

    .colorMian {
      color: #E65A1E;
    }
</style>
